package com.cdd.agent.api.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cdd.common.domain.entity.AppOrder;
import com.cdd.agent.api.mapper.AppOrderMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Arrays;
import java.util.List;

/**
 * @author cdd
 * @date 2025-08-08 10:56
 */
@Service
public class AppOrderService {

    @Resource
    private AppOrderMapper appOrderMapper;

    public AppOrderMapper getBaseMapper() {
        return appOrderMapper;
    }

    public BigDecimal rechargeToday(String subUserIds) {
        if (StringUtils.isEmpty(subUserIds)) {
            return BigDecimal.ZERO;
        }
        //今日的订单
        List<AppOrder> appOrders = appOrderMapper.selectList(
                new LambdaQueryWrapper<AppOrder>()
                        .between(
                                AppOrder::getChongzhitime,
                                LocalDateTime.now().with(LocalTime.MIN),
                                LocalDateTime.now().with(LocalTime.MAX)
                        )
                        .eq(AppOrder::getStatus, 2)
                        .eq(AppOrder::getState, 2)
                        .in(AppOrder::getUserid, Arrays.asList(subUserIds.split(",")))
        );
        return appOrders.stream().map(AppOrder::getMoney).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
    }

    public BigDecimal withdrawToday(String subUserIds) {
        if (StringUtils.isEmpty(subUserIds)) {
            return BigDecimal.ZERO;
        }
        return new BigDecimal("0");
    }
}
